package com.example.gaojt.androiddemo.boostDemo.aa;

import android.content.Context;

import java.util.Locale;

public class ProcAdviceKeepFilter extends ProcBaseFilter {

    private String[] mKeywordPkgs = new String[] {"contact", "clock", "weather"};

    public ProcAdviceKeepFilter(Context ctx) {
        super(ctx);
    }

    @Override
    public boolean doFilter(ProcessModel.ProcessInfo processInfo) {
        if (processInfo.mPkgList == null || processInfo.mPkgList.size() == 0) {
            return false;
        }

        for (String pkgName : processInfo.mPkgList) {

            for (int i = 0,length = mKeywordPkgs.length; i < length; i++) {
                String keyword = mKeywordPkgs[i];
                if (pkgName.toLowerCase(Locale.US).contains(keyword)) {
                    if (processInfo.mCleanSuggest == ProcessModel.ProcessInfo.PROC_SUGGEST_CLEAN) {
                        processInfo.mCleanSuggest = ProcessModel.ProcessInfo.PROC_SUGGEST_ADVICE_KEEP;
                    }
                    ProcessModel.ProcessAdvInfo processAdvInfo = new ProcessModel.ProcessAdvInfo();
                    processAdvInfo.mDescription = ProcessModel.ProcessAdvInfo.ADVICE_KEEP;
                    processAdvInfo.mStatus = i + 2;
                    processInfo.mAdvanceInfo.add(processAdvInfo);
                    return false;
                }
            }

            int value = IniManager.getIniMark(mContext,pkgName);
            if (value == IniManager.PROCESS_UNCHECKED || value == IniManager.PROCESS_NECESSARY_APP) {
                if (processInfo.mCleanSuggest == ProcessModel.ProcessInfo.PROC_SUGGEST_CLEAN) {
                    processInfo.mCleanSuggest = ProcessModel.ProcessInfo.PROC_SUGGEST_ADVICE_KEEP;
                }
                ProcessModel.ProcessAdvInfo processAdvInfo = new ProcessModel.ProcessAdvInfo();
                processAdvInfo.mDescription = ProcessModel.ProcessAdvInfo.ADVICE_KEEP;
                processAdvInfo.mStatus = 1;
                processInfo.mAdvanceInfo.add(processAdvInfo);
                return false;
            }

        }

        return false;
    }

}
